import { ElMessage } from 'element-plus'
import {$http} from '@/utils/axios.js'
import {debounce, gatewayPrefix, userMiddleContextPath,currentUser,token,authorization} from '@/utils/commConstance'

// 引入useStore 方法
import { useStore } from 'vuex' 

const tagType = ['','success','info','danger','warning']

//校验是否登录
function isLogin(){
    const user = sessionStorage.getItem(currentUser)
    const t = sessionStorage.getItem(token)
    const sign = sessionStorage.getItem(authorization)
    if(user === null || user === undefined){
        return false
    }
    if(t === null || t === undefined){
        return false
    }
    if(sign === null || sign === undefined){
        return false
    }
    return true
}


//获取文章类型
function getArticleType(){
    const store = useStore()
    $http.get(`${gatewayPrefix}/${userMiddleContextPath}/articleOperate/getAllArtTypes`).then((result) =>{
        result.forEach(element => {
            element.type = tagType[Math.floor(Math.random()*5 + 0)] 
        });
        store.commit('getArtTypeList',result)
    }).catch( (err) =>{
        if(JSON.stringify(err).indexOf('Network Error') !== -1){
            ElMessage.error(err.response || '获取文章类型失败')
        }  
    })
}

// 会员套餐
const memberList=[
    {name: '普通会员',money: 10, time: '月'},
    {name: '普通会员',money: 50, time: '半年'},
    {name: '普通会员',money: 90, time: '一年'},
    {name: '白银会员',money: 15, time: '月'},
    {name: '白银会员',money: 80, time: '半年'},
    {name: '白银会员',money: 140, time: '一年'},
    {name: '黄金会员',money: 20, time: '月'},
    {name: '黄金会员',money: 110, time: '半年'},
    {name: '黄金会员',money: 200, time: '一年'},
    {name: '黄金会员',money: 20, time: '月'},
    {name: '黄金会员',money: 110, time: '半年'},
    {name: '黄金会员',money: 200, time: '一年'},

    {name: '黄金会员',money: 20, time: '月'},
    {name: '黄金会员',money: 110, time: '半年'},
    {name: '黄金会员',money: 200, time: '一年'},
    {name: '黄金会员',money: 20, time: '月'},
    {name: '黄金会员',money: 110, time: '半年'},
    {name: '黄金会员',money: 200, time: '一年'},
]

export {
    getArticleType,
    memberList,
    isLogin
}